<template>
  <div>
    <el-button style="margin-bottom: 10px" @click="back">返回</el-button>
    <el-card>
      <el-form :inline="true" :model="query" label-width="100px" size="small">
        <!-- 公司级别 -->
        <el-form-item class="query-form-item">
          <span>公司级别：</span>
          <el-select
            v-model="query.companyLevel"
            placeholder="请选择公司级别"
            @change="onSubmit"
            clearable
          >
            <el-option label="全球公司" value="1"></el-option>
            <el-option label="省级公司" value="2"></el-option>
            <el-option label="市级公司" value="3"></el-option>
            <el-option label="县级公司" value="4"></el-option>
          </el-select>
        </el-form-item>
        <!-- 公司类型 -->
        <el-form-item class="query-form-item">
          <span>公司类型：</span>
          <el-select
            v-model="query.companyType"
            placeholder="请选择公司类型"
            @change="onSubmit"
            clearable
          >
            <el-option label="孵化" value="0"></el-option>
            <el-option label="临时" value="1"></el-option>
            <el-option label="正式" value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form :inline="true" :model="query" size="small">
        <!-- 关键词检索 -->
        <el-form-item>
          <span> 公司名称：</span>
          <el-form-item class="query-form-item">
            <el-input
              v-model="query.companyName"
              placeholder="请输入公司名称"
              prefix-icon="el-icon-search"
              clearable
              style="magrin-left: 30px"
            ></el-input>
          </el-form-item>
        </el-form-item>
        <!-- 查询框 -->
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-refresh"
            @click="onRest"
          ></el-button>
          <el-button type="primary" icon="el-icon-search" @click="onSubmit"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>

      <!-- table表单 -->
      <el-table
        ref="singleTable"
        :data="tableData"
        v-loading="loading"
        style="width: 100%"
      >
        <el-table-column
          label="序号"
          type="index"
          align="center"
          width="50"
          fixed
        >
        </el-table-column>
        <el-table-column prop="createtime" label="变更时间" align="center">
          <template slot-scope="scope">
            <span>{{
              scope.row.createtime | formatDateStr("yyyy-MM-dd hh:mm:ss")
            }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="changetype" label="变更类型" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.changetype == 0" style="color: #ffa659"
              >新增</span
            >
            <span v-else-if="scope.row.changetype == 1" style="color: #4acf1e"
              >编辑</span
            >
          </template>
        </el-table-column>
        <el-table-column prop="newlevel" align="center" label="品牌公司级别">
          <template slot-scope="scope">
            <span v-if="scope.row.newlevel == 1" style="color: #4acf1e"
              >全球公司</span
            >
            <span v-else-if="scope.row.newlevel == 2" style="color: #4acf1e"
              >省级公司</span
            >
            <span v-else-if="scope.row.newlevel == 3" style="color: #4acf1e"
              >市级公司</span
            >
            <span v-else-if="scope.row.newlevel == 4" style="color: #4acf1e"
              >县级公司</span
            >
          </template>
        </el-table-column>
        <el-table-column prop="newcompanytype" align="center" label="公司类型">
          <template slot-scope="scope">
            <span v-if="scope.row.newcompanytype == 0" style="color: #ffa659"
              >孵化</span
            >
            <span
              v-else-if="scope.row.newcompanytype == 1"
              style="color: #4acf1e"
              >临时</span
            >
            <span
              v-else-if="scope.row.newcompanytype == 2"
              style="color: #4acf1e"
              >正式</span
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="companyid"
          align="center"
          :show-overflow-tooltip="true"
          label="公司ID"
        ></el-table-column>
        <el-table-column
          prop="newcompanyname"
          align="center"
          :show-overflow-tooltip="true"
          label="公司名称"
        ></el-table-column>

        <el-table-column align="center" label="操作" width="120" fixed="right">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              @click="lookInfo(scope.$index, scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        class="pagination-container"
        background
        :page-size="query.pageSize"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total,sizes,prev, pager, next, jumper"
        :current-page="query.currentPage"
        :page-sizes="[5, 10, 20, 30, 50]"
        :total="totalNumber"
      ></el-pagination>
    </el-card>

    <el-dialog
      title="查看"
      :visible.sync="dialogForm"
      top="5vh"
      width="50%"
      :close-on-click-modal="false"
    >
      <template slot="title">
        <div class="avue-crud__dialog__header">
          <span class="el-dialog__title">
            <span
              style="
                display: inline-block;
                background-color: #3478f5;
                width: 3px;
                height: 20px;
                margin-right: 5px;
                float: left;
                margin-top: 2px;
              "
            ></span>
            查看
          </span>
        </div>
      </template>
      <el-card>
        <el-form :model="addData" class="demo-ruleForm" label-width="200px">
          <el-form-item label="新增时间 : ">
            <span v-if="addData.createtime != null">{{
              addData.createtime | formatDateStr("yyyy-MM-dd hh:mm:ss")
            }}</span>
            <span v-else>无</span>
          </el-form-item>

          <el-form-item label="品牌公司级别 : ">
            <span v-if="addData.primevallevel == 1" style="color: #4acf1e"
              >全球公司</span
            >
            <span v-else-if="addData.primevallevel == 2" style="color: #4acf1e"
              >省级公司</span
            >
            <span v-else-if="addData.primevallevel == 3" style="color: #4acf1e"
              >市级公司</span
            >
            <span v-else-if="addData.primevallevel == 4" style="color: #4acf1e"
              >县级公司</span
            >
          </el-form-item>

          <el-form-item label="品牌公司类型 : ">
            <span v-if="addData.primevacompanytype == 0" style="color: #ffa659"
              >孵化</span
            >
            <span
              v-else-if="addData.primevacompanytype == 1"
              style="color: #4acf1e"
              >临时</span
            >
            <span
              v-else-if="addData.primevacompanytype == 2"
              style="color: #4acf1e"
              >正式</span
            >
          </el-form-item>

          <el-form-item label="品牌公司名称 : ">
            <span v-if="addData.primevabelongbrandname != null">{{
              addData.primevabelongbrandname
            }}</span>
            <span v-else>无</span>
          </el-form-item>

          <el-form-item label="开发关系ID : ">
            <span v-if="addData.primevadeveloprelationid != null">{{
              addData.primevadeveloprelationid
            }}</span>
            <span v-else>无</span>
          </el-form-item>

          <el-form-item label="开发关系公司名称 : ">
            <span v-if="addData.primevadeveloprelationname != null">{{
              addData.primevadeveloprelationname
            }}</span>
            <span v-else>无</span>
          </el-form-item>

          <el-form-item label="开发关系公司级别 : ">
            <span
              v-if="addData.primevadeveloprelationlevel == 1"
              style="color: #4acf1e"
              >全球公司</span
            >
            <span
              v-else-if="addData.primevadeveloprelationlevel == 2"
              style="color: #4acf1e"
              >省级公司</span
            >
            <span
              v-else-if="addData.primevadeveloprelationlevel == 3"
              style="color: #4acf1e"
              >市级公司</span
            >
            <span
              v-else-if="addData.primevadeveloprelationlevel == 4"
              style="color: #4acf1e"
              >县级公司</span
            >
          </el-form-item>

          <el-form-item label="创始人ID : ">
            <span v-if="addData.companyoriginatorid != null">{{
              addData.companyoriginatorid
            }}</span>
            <span v-else>无</span>
          </el-form-item>

          <el-form-item label="创始人商城名称 : ">
            <span v-if="addData.originatorcompanyname != null">{{
              addData.originatorcompanyname
            }}</span>
            <span v-else>无</span>
          </el-form-item>
        </el-form>
      </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button type="warning" @click="closeCheck">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  getOptionRecord,
  getRecordDetail,
} from "../../api/handWork/handWorkList";
export default {
  data() {
    return {
      tableData: [],
      query: {
        currentPage: 1,
        pageSize: 5,
        companyLevel: "",
        companyType: "",
        companyName: "",
      },
      totalNumber: 0,
      loading: false,
      dialogForm: false, //如果是新增状态类型即dialog
      addData: {}, //新增类型的dialog弹窗里面的信息
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //搜索
    onSubmit() {
      this.query.currentPage = 1;
      this.getList();
    },
    getList() {
      getOptionRecord(this.query)
        .then((res) => {
          console.log(res);
          if (res.code != 0) {
            this.$message.error(res.message);
            this.loading = false;
            return false;
          }
          this.tableData = res.data.list;
          this.totalNumber = res.data.total;
        })
        .catch(() => {
          this.loading = false;
          this.tableData = [];
        });
    },

    getData(recordId) {
      getRecordDetail({ recordId })
        .then((res) => {
          console.log(res, "新增记录数据");
          if (res.code != 0) {
            this.$message.error(res.message);
            this.loading = false;
            return false;
          }
          this.addData = res.data;
        })
        .catch(() => {
          // this.loading = false
        });
    },
    back() {
      this.$router.push({
        name: "公司关系设置",
      });
    },
    //刷新
    onRest() {
      this.query = {
        currentPage: 1,
        pageSize: 5,
        companyLevel: "",
        companyType: "",
        companyName: "",
      };
      this.getList();
    },
    handleSizeChange(val) {
      this.query.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.query.currentPage = val;
      this.getList();
    },
    //查看操作
    lookInfo(index, row) {
      //判断
      if (row.changetype == 1) {
        this.$router.push({
          path: "lookInfo",
          query: { recordid: row.recordid },
        });
      } else if (row.changetype == 0) {
        this.getData(row.recordid);
        this.dialogForm = true;
      }
    },
    //取消按钮
    closeCheck() {
      this.dialogForm = false;
    },
  },
};
</script>